<?php


namespace app\admin\model\user;

use app\admin\model\BaseModel;
use think\facade\Db;
/**
 * 获客页
 * Class Admin
 * @package app\admin\model
 */
class UserDefinite extends BaseModel
{
    
    public static function signPage($where)
    {
        $model = new self;
        $model = $model->alias("d")->join("user u","u.uid = d.uid");
        $model = $model->where("d.mold","sign");
        if ($where['phone'] != '') $model = $model->where('u.phone',"like","%$where[phone]%");
        if ($where['start_time'] != '') $model = $model->where('d.create_time','>',strtotime($where['start_time']." 00:00:00"));
        if ($where['end_time'] != '') $model = $model->where('d.create_time','<', strtotime($where['start_time']." 23:59:59"));

        $count = self::counts($model);
        if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'],(int)$where['limit']);
        $model = $model->field('u.phone,d.*');

        $data = $model->select()->each(function ($item) {
            //获取签到配置
            $signConfig = SystemConfigMore(['sign_periods_days','sign_initial_gold','sign_gold_add_number']);
            $signList = [(int)$signConfig['sign_initial_gold']];
            
            //设置签到
            for ($i=1;$i<$signConfig['sign_periods_days'];$i++) {
                $signList[$i] = $signConfig['sign_initial_gold'] + $i*$signConfig['sign_gold_add_number'];
            }
            
            //判断签到了几次
            $signList  = array_flip($signList);
            $item['sign_number'] = $signList[(int)$item['number']]+1;
            
        });
        $data = $data ? $data->toArray() : [];
        return compact("data","count");  
    }

   

}